<template>
	<div>
		<!-- 面包屑导航区域 -->
		<el-breadcrumb separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>咨询系统</el-breadcrumb-item>
			<el-breadcrumb-item>员工签到</el-breadcrumb-item>
		</el-breadcrumb>
		<el-card class="box-card">
			<!-- 搜索与添加区域 -->
			<el-form :inline="true" :model="queryInfo" class="demo-form-inline">
				<el-form-item label="用户名:">
					<el-input v-model="queryInfo.UserName"></el-input>
				</el-form-item>
				<el-form-item label="签到时间:">
					 <el-col :span="11">
					       <el-date-picker type="date" placeholder="选择日期" v-model="queryInfo.CheckinTimeStart" style="width: 100%;"></el-date-picker>
					     </el-col>
					     <el-col class="line" :span="2">-</el-col>
					     <el-col :span="11">
					       <el-date-picker type="date" placeholder="选择日期" v-model="queryInfo.CheckinTimeEnd" style="width: 100%;"></el-date-picker>
					     </el-col>
				</el-form-item>
				<el-form-item label="签到状态">
					<el-select v-model="queryInfo.CheckState" placeholder="请选择">
						<el-option label="全部" value=""></el-option>
						<el-option label="已签到" value="已签到"></el-option>
						<el-option label="未签到" value="未签到"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit" icon="el-icon-search" plain>查询</el-button>
				</el-form-item>
				
		
			</el-form>
			<!-- 用户列表区域 -->
			<el-table :data="userlist" border stripe>
				<el-table-column label="用户名" prop="UserName"></el-table-column>
				<el-table-column label="签到状态" prop="CheckState"></el-table-column>
				<el-table-column label="签到时间" prop="CheckinTime"></el-table-column>
				<el-table-column label="签退时间" prop="CheckOutTime"></el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<!-- 分配角色按钮 -->
						<el-button type="warning" icon="el-icon-setting" size="mini" @click="CheckOut(scope.row)" plain>签退</el-button>
					</template>
				</el-table-column>
			</el-table>
			<!-- 分页区域 -->
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum"
			 :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</el-card>
	
	
	</div>
</template>

<script>
	export default{
		data(){
			return{
				queryInfo:{
					UserName:'',
					CheckinTimeStart:'',
					CheckinTimeEnd:'',
					CheckState:''
				},
				page:1,
				limit:10,
				total:0,
				userlist:[]
				
			}
		},
		methods:{
			//多条件搜索
			onSubmit() {
				this.getUserChecks();
			},
			async getUserChecks() {
				const {
					data: res
				} = await this.$http.get('api/UserChecks/GetUserChecks', {
					params: {
						UserName: this.queryInfo.UserName,
						CheckState: this.queryInfo.CheckState,
						CheckinTimeStart: this.queryInfo.CheckinTimeStart,
						CheckinTimeEnd: this.queryInfo.CheckinTimeEnd,
						page: this.page,
						limit: this.limit
					}
				})
				if (res.status !== 200) {
					return this.$message.error('获取用户列表失败！')
				}
				this.userlist = res.data
				this.total = res.total
				console.log(res)
			},
			//监听 pagesize 改变的事件
			handleSizeChange(newSize) {
				//console.log(newSize)
				this.limit = newSize
				this.getUserChecks()
			},
			//监听 页码值 改变的事件
			handleCurrentChange(newPage) {
				//console.log(newPage)
				this.page = newPage
				this.getUserChecks()
			},
			async CheckOut(row) {
							this.CheckInfo=row
							const {
								data: res
							} = await this.$http.post('api/UserChecks/CheckOuts', this.CheckInfo)
							if (res.code == 0) {
								this.$message.success(res.msg)
							} else {
								this.$message.error(res.msg)
							}
							this.getUserChecks()
						}
		},
		created() {
			this.getUserChecks();
		}
	}
</script>

<style>
</style>
